From fc58bdc3edfd3677d1db4ffefa60d58926e81a0a Mon Sep 17 00:00:00 2001 From: robertlipe Date: Mon, 22 Jul 2013 03:55:56 +0000 Subject: [PATCH] Rethink time interpolation in arcdist in light of better time functions. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4464 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/arcdist.cc | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/gpsbabel/arcdist.cc b/gpsbabel/arcdist.cc index b2812494f..60239360e 100644 --- a/gpsbabel/arcdist.cc +++ b/gpsbabel/arcdist.cc @@ -235,28 +235,19 @@ arcdist_process(void) /* Interpolate time */ if (ptsopt) { wp->creation_time = ed->arcpt2->creation_time; - wp->microseconds = ed->arcpt2->microseconds; } else { - double wptimes = ed->arcpt1->creation_time + - ed->frac * (ed->arcpt2->creation_time - ed->arcpt1->creation_time); - wp->creation_time = floor(wptimes); - wp->microseconds = 1000000.0 * (wptimes - wp->creation_time); - if (ed->arcpt1->microseconds <= ed->arcpt2->microseconds) { - wp->microseconds += ed->arcpt1->microseconds + - ed->frac * (ed->arcpt1->microseconds - ed->arcpt1->microseconds); - } else { - wp->microseconds += ed->arcpt1->microseconds + - ed->frac * (1000000 - ed->arcpt1->creation_time + - ed->arcpt2->creation_time); - wp->creation_time--; - } - - wp->creation_time += wp->microseconds / 1000000; - wp->microseconds %= 1000000; + // Apply the multiplier to the difference between the times + // of the two points. Add that to the first for the + // interpolated time. + int scaled_time = ed->frac * + ed->arcpt1->creation_time.msecsTo(ed->arcpt2->creation_time); + QDateTime new_time(ed->arcpt1->creation_time.addMSecs(scaled_time)); + wp->SetCreationTime(new_time); } } if (global_opts.debug_level >= 1) { - warning("Including waypoint %s at dist:%f lat:%f lon:%f\n", wp->shortname, ed->distance, wp->latitude, wp->longitude); + warning("Including waypoint %s at dist:%f lat:%f lon:%f\n", + wp->shortname, ed->distance, wp->latitude, wp->longitude); } } xfree(ed); -- 2.30.2